﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace project4
{
    /// <summary>
    /// 抽象主题
    /// </summary>
    public abstract class Subject
    {
        /// <summary>
        /// 观察者列表
        /// </summary>
        List<Updated> observers = new List<Updated>();

        /// <summary>
        /// 添加一个观察者
        /// </summary>
        /// <param name="obs"></param>
        public void AddObserver(Updated obs)
        {
            observers.Add(obs);
        }

        /// <summary>
        /// 删除一个已有的观察者
        /// </summary>
        /// <param name="obs"></param>
        public void RemoveObserver(Updated obs)
        {
            observers.Remove(obs);
        }

        /// <summary>
        /// 通知所有的观察者--数据已经更新-->具体的处理操作由各个观察者自己处理
        /// </summary>
        /// <param name="val"></param>
        protected virtual void Notify(User user)
        {
            foreach (Updated obs in observers)
                obs.BalanceUpdated(user);
        }
    }
}
